package com.quartet.config;

import com.quartet.api.MapServerException;
import com.quartet.api.ResultErrorEnum;
import com.quartet.utils.SecurityUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AuthInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        String currentUsername = SecurityUtils.getCurrentUsername();
        //如果currentUsername为空
        if (StringUtils.isBlank(currentUsername)) {
            throw new MapServerException(ResultErrorEnum.BMKPM003);
        }
        return true;
    }
}
